<?php

namespace App\Http\Controllers\Plan;

use App\Http\Controllers\Controller;
use App\Services\Plan\PlanServices;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class PlanController extends Controller
{
    /**
     * 创建.
     *
     * @param Request $request
     * @param PlanServices $services
     * @return JsonResponse
     */
    public function createPlan(Request $request, PlanServices $services): JsonResponse
    {
        $res = $services->createPlan($request);

        if (!$res) {
            return $this->responseError([], $services->getError()->getMessage());
        }

        return $this->responseSuccess();
    }

    /**
     * 列表.
     *
     * @param Request $request
     * @param PlanServices $services
     * @return JsonResponse
     */
    public function planList(Request $request, PlanServices $services): JsonResponse
    {
        $res = $services->planList($request);

        if (!$res) {
            return $this->responseError([], $services->getError()->getMessage());
        }

        return $this->responseSuccess($res);
    }

    /**
     * 待办事项提交到已完成.
     *
     * @param Request $request
     * @param PlanServices $services
     * @return JsonResponse
     */
    public function completePlan(Request $request, PlanServices $services): JsonResponse
    {
        $res = $services->completePlan($request);

        if (!$res) {
            return $this->responseError([], $services->getError()->getMessage());
        }

        return $this->responseSuccess();
    }

    /**
     * 删除.
     *
     * @param Request $request
     * @param PlanServices $services
     * @return JsonResponse
     */
    public function delPlan(Request $request, PlanServices $services): JsonResponse
    {
        $res = $services->delPlan($request);

        if (!$res) {
            return $this->responseError([], $services->getError()->getMessage());
        }

        return $this->responseSuccess();
    }
}
